<template>
  <div>
    <!-- 
          data:数据
          row-key：一行的唯一标识
          border：加边框
          default-expand-all：默认展开所有数据
           :tree-props="{ children: '由哪个字段来判断是否有子节点' }"
       -->
    <el-table
      :data="list"
      style="width: 100%"
      row-key="id"
      border
      :tree-props="{ children: 'children' }"
    >
      <el-table-column prop="id" label="用户编号"> </el-table-column>
      <el-table-column prop="username" label="用户名称"> </el-table-column>
      <el-table-column prop="rolename" label="所属角色"> </el-table-column>

      <el-table-column label="状态">
        <template slot-scope="scope">
          <el-button type="primary" v-if="scope.row.status == 1"
            >启用</el-button
          >
          <el-button type="info" v-else>禁用</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="handleEdit(scope)">编辑</el-button>
          <el-button type="danger" @click="handleDelete(scope)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { requserdelete } from "../../../http/api";
import { successAlert } from "../../../utils/alert";
export default {
  components: {},
  props: ["list"],
  data() {
    return {};
  },
  methods: {
    //7.1点击了编辑按钮
    handleEdit(scope) {
      //   scope.$index 下标
      // scope.row 那条数据 item
      // console.log(scope);
      //通知父组件点了编辑
      this.$emit("willUpdate", scope.row.uid);
    },
    handleDelete(scope) {
      this.$confirm("你确定要删除么？", "删除提示", {
        confirmButtonText: "删除",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //开始删除
          requserdelete({
            uid:scope.row.uid
          }).then((res) => {
            if (res.data.code == 200) {
              //弹成功
              successAlert(res.data.msg);
              //重新获取list
              this.$emit("init");
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
  mounted() {},
  computed: {},
  watch: {},
};
</script>
<style scoped lang="less">
@import "../../../less/index.less";
</style>